package model.tests;

import graphs.BarGraph;
import graphs.TagCloud;
import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.List;
import java.util.Map;
import model.Model;
import junit.framework.Assert;
import junit.framework.TestCase;

public class ProcessTests extends TestCase
{
    private Model myModel;
    private URL myCSVURL;
    private URL myTXTURL;

    protected void setUp() throws Exception
    {
        super.setUp();
        myModel = new Model();
        File txtfile = new File("data/names.txt");
        try
        {
            myCSVURL = new URL("http://www.duke.edu/~vr28/2DTestData.csv");
            myTXTURL = txtfile.toURI().toURL();
        }
        catch (MalformedURLException e)
        {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

    protected void tearDown() throws Exception
    {
        super.tearDown();
    }

    public void testGetDataCSV()
    {
        Map<Object, List<Object>> results = myModel.getData(myCSVURL,
                new BarGraph());
        Assert.assertEquals(4, results.size());
        Assert.assertTrue(results.containsKey("bob"));
        Assert.assertEquals(2.6, results.get("bob").get(0));
        Assert.assertTrue(results.containsKey("jim"));
        Assert.assertEquals(6.00, results.get("jim").get(0));
    }

    public void testGetDataTXT()
    {
        Map<Object, List<Object>> results = myModel.getData(myTXTURL,
                new BarGraph());
        Assert.assertEquals(4428, results.size());
        Assert.assertTrue(results.containsKey("Ariel"));
        Assert.assertEquals(0.0, results.get("Ariel").get(5));
        Assert.assertTrue(results.containsKey("Bella"));
        Assert.assertEquals(344.0, results.get("Bella").get(0));
    }

    public void testTagData()
    {
        File file = new File("data/TagData.txt");
        Map<Object, List<Object>> results = null;
        try
        {
            results = myModel.getData(file.toURI().toURL(), new TagCloud());
        }
        catch (MalformedURLException e)
        {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        Assert.assertEquals(11, results.size());
        Assert.assertTrue(results.containsKey("cookies"));
        Assert.assertEquals(2.0, results.get("cookies").get(0));
        Assert.assertNull(results.get(""));
        Assert.assertTrue(results.containsKey("fun"));
        Assert.assertEquals(2.0, results.get("fun").get(0));
    }

}
